<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <span>
        <el-form ref="form" :model="form" label-width="80px">
          <el-form-item label="关键字">
            <el-input
              v-model="keyword"
              style="width: 220px"
              placeholder="根据编辑搜索"
            ></el-input>
          </el-form-item>
        </el-form>
      </span>
      <span class="you">
        <el-button size="medium" @click="qc">清除</el-button>
        <el-button size="medium" type="primary" @click="gjz">搜索</el-button>
      </span>
    </div>
    <div
      role="alert"
      class="el-alert alert el-alert--info is-light"
      style="margin-bottom: 15px"
    >
      <i class="el-alert__icon el-icon-info"></i>
      <div class="el-alert__content">
        <span class="el-alert__title">数据一共 {{ counts }} 条</span
        ><!----><!----><i
          class="el-alert__closebtn el-icon-close"
          style="display: none"
        ></i>
      </div>
    </div>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="id" label="编号" width="190"> </el-table-column>
      <el-table-column label="题型">
        <template v-slot="scoped">
          {{ tixin(scoped.row.questionType) }}
        </template>
      </el-table-column>
      <el-table-column label="题目编号" width="190">
        <template v-slot="scoped">
          <el-link
            v-for="item in scoped.row.questionIDs"
            :key="item.number"
            type="primary"
            :underline="false"
            @click="yl(item)"
            >{{ item.number }}</el-link
          >
        </template>
      </el-table-column>
      <el-table-column prop="addTime" label="录入时间" width="190">
      </el-table-column>
      <el-table-column prop="totalSeconds" label="答题时间(s)">
      </el-table-column>
      <el-table-column prop="accuracyRate" label="正确率(%)"> </el-table-column>
      <el-table-column prop="userName" label="录入人"> </el-table-column>
      <el-table-column label="操作">
        <template v-slot="scoped">
          <el-button
            type="danger"
            icon="el-icon-delete"
            circle
            @click="del(scoped.row)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="q.page"
        :page-sizes="[20, 30, 50, 100]"
        :page-size="q.pagesize"
        layout=" prev, pager, next, sizes, jumper"
        :total="counts"
      >
      </el-pagination>
    </div>
    <el-dialog title="提示" :visible.sync="dialogVisible" width="70%">
      <yulan ref="yulan" @bi="biY"></yulan>
    </el-dialog>
  </el-card>
</template>

<script>
import { randoms, removeRandoms, detail } from '@/api/hmmm/questions'
import yulan from './ztlb/yulan.vue'
export default {
  components: {
    yulan
  },
  data () {
    return {
      counts: 1, // 总条数
      form: {},
      tableData: [],
      q: {
        page: 1,
        pagesize: 10,
        keyword: ''
      },
      keyword: '', // 关键字
      dialogVisible: false
    }
  },
  methods: {
    biY () {
      this.dialogVisible = false
    },
    handleSizeChange (val) {
      // console.log(`每页 ${val} 条`)
      this.q.pagesize = val
      this.zhutiList()
    },
    handleCurrentChange (val) {
      // console.log(`当前页: ${val}`)
      this.q.page = val
      this.zhutiList()
    },
    async zhutiList () {
      const res = await randoms(this.q)
      console.log(res.data.items, res.data.counts, 55555)
      this.counts = res.data.counts
      this.tableData = res.data.items
    },
    tixin (id) {
      if (id === '1') {
        return '单选'
      } else if (id === '2') {
        return '多选'
      } else {
        return '简答'
      }
    },
    async del (data) {
      const res = await removeRandoms(data)
      console.log(res, 66666666)
      if (res.status === 200) {
        this.$message({
          message: '删除成功',
          type: 'success'
        })
      }
      this.zhutiList()
    },
    async gjz () {
      // console.log('5555')
      this.q.keyword = this.keyword
      const res = await this.zhutiList(this.q)
      console.log(res, 99999999)
    },
    async qc () {
      // console.log('5555')
      this.q.keyword = ''
      this.keyword = ''
      const res = await this.zhutiList(this.q)
      console.log(res, 99999999)
    },
    async yl (item) {
      const data = {
        id: item.id
      }
      this.dialogVisible = true
      const res = await detail(data)
      console.log(data, res, 555655665)
      this.$nextTick(() => {
        this.$refs.yulan.previeList = res.data
      })
    }
  },
  created () {
    this.zhutiList()
  }
}
</script>

<style scoped lang="scss">
.box-card {
  margin: 20px;
}
.clearfix {
  display: flex;
  justify-content: space-between;
}
.el-form-item--medium {
  margin-bottom: 0px;
}
.you {
  margin-left: 750px;
}
.block {
  display: flex;
  justify-content: flex-end;
}
</style>
